﻿#define USE_SLIMDX
//#define USE_XNA

#region Dependencies

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

using XNA = Microsoft.Xna.Framework;
using SDX = SlimDX;
using SysDrawing = System.Drawing;
using PhysX = StillDesign.PhysX;
using BEPU = BEPUphysics;

#if USE_SLIMDX
using SlimDX;
using SlimDX.Direct3D10;
using SlimDX.DirectInput;
using SlimDX.DirectSound;
using SlimDX.DirectWrite;
using SlimDX.DXGI;
using SlimDX.Multimedia;
using SlimDX.Windows;
using SlimDX.X3DAudio;
using SlimDX.XACT3;
using SlimDX.XAPO;
using SlimDX.XAudio2;
#endif

#if USE_XNA
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Design;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using Xen2D;
using XenAspects;
using XenGameBase;
#endif

#endregion // Dependencies

using Blackrain;
using Blackrain.Core;
//using Blackrain.Core.IO;
//using Blackrain.Core.Containers;
//using Blackrain.Core.Memory;

namespace Blackrain.Core.Content
{
    public enum EntityType
    {
        Model,
        SoundEffect,
        VisualEffect,
        Configuration,
        PlayerData,
        Material,
        Texture,
        Shader,
        Animation,
        Group,
        MocapProfile,
        Scene,
        Script,
    }

    public struct EntityCacheObject
    {
        public string fileName;
        public EntityType type;
        //public Entity entity;
    }

    /// <summary>
    /// Base manager for all content that gets imported into the engine.
    /// </summary>
    public class ContentManager
    {
        private Dictionary<string, EntityCacheObject> entityCacheList = new Dictionary<string, EntityCacheObject>();

        // content directory is parent to the game executable.
        private const string Content_BaseSearchDirectory = @"data/";

        public ContentManager()
        {
        }

        public void Load()
        {

        }

        /// <summary>
        /// Adds a content file into the cache.
        /// NOTE: This auto-detects the file type as it gets imported.
        /// </summary>
        /// <param name="fileName"></param>
        public void Add( string fileName )
        {
            string[] fileName_a = fileName.Split( '/' );

            if( fileName_a[ 0 ] == "models" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Model;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "sfx" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.SoundEffect;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "vfx" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.VisualEffect;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "config" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Configuration;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "player_data" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.PlayerData;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "materials" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Material;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "textures" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Texture;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "shaders" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Shader;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "animations" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Animation;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "groups" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Group;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "mocap_profiles" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.MocapProfile;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "scene" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Scene;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
            else if( fileName_a[ 0 ] == "script" )
            {
                EntityCacheObject eco = new EntityCacheObject();
                eco.fileName = Content_BaseSearchDirectory + fileName;
                eco.type = EntityType.Script;

                entityCacheList.Add( fileName_a[ 1 ], eco );
            }
        }
    }
}
